package vanjalee.bs.com.control.model;

import java.util.Comparator;

public class Part extends Item {

	private String name;
	private int level;
	private int speed;
	private int hp;
	private int capacity;
	private int armor;
	private int weight;

	private PartType partType;

	public Part() {
	}
	
	public Part(String name, int level, int speed, int hp, int capacity,
			int armor, int weight, PartType partType, ItemType itemType,
			String whereToGet, String furtherInfo, boolean upgradable,
			boolean special) {
		this.name = name;
		this.level = level;
		this.speed = speed;
		this.hp = hp;
		this.capacity = capacity;
		this.armor = armor;
		this.weight = weight;
		this.partType = partType;
		this.itemType = itemType;
		this.whereToGet = whereToGet;
		this.furtherInfo = furtherInfo;
		this.upgradable = upgradable;
		this.special = special;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getLevel() {
		return level;
	}

	public void setLevel(int level) {
		this.level = level;
	}

	public int getSpeed() {
		return speed;
	}

	public void setSpeed(int speed) {
		this.speed = speed;
	}

	public int getHp() {
		return hp;
	}

	public void setHp(int hp) {
		this.hp = hp;
	}

	public int getCapacity() {
		return capacity;
	}

	public void setCapacity(int capacity) {
		this.capacity = capacity;
	}

	public int getArmor() {
		return armor;
	}

	public void setArmor(int armor) {
		this.armor = armor;
	}

	public int getWeight() {
		return weight;
	}

	public void setWeight(int weight) {
		this.weight = weight;
	}

	public PartType getPartType() {
		return partType;
	}

	public void setPartType(PartType partType) {
		this.partType = partType;
	}

	@Override
	public String toString() {
		return "Part [name=" + name + ", level=" + level + ", speed=" + speed
				+ ", hp=" + hp + ", capacity=" + capacity + ", armor=" + armor
				+ ", weight=" + weight + ", partType=" + partType
				+ ", itemType=" + itemType + ", whereToGet=" + whereToGet
				+ ", furtherInfo=" + furtherInfo + ", upgradable=" + upgradable
				+ ", special=" + special + "]";
	}
	public static Comparator<Part> getComparator(
			SortParameter... sortParameters) {
		return new PartComparator(sortParameters);
	}

	public enum SortParameter {
		NAME_ASCENDING, NAME_DESCENDING, LEVEL_ASCENDING, LEVEL_DESCENDING, SPEED_ASCENDING, SPEED_DESCENDING, HP_ASCENDING, HP_DESCENDING, CAPACITY_ASCENDING, CAPACITY_DESCENDING, ARMOR_ASCENDING, ARMOR_DESCENDING, WEIGHT_ASCENDING, WEIGHT_DESCENDING, ITEMTYPE_ASCENDING, ITEMTYPE_DESCENDING, WHERETOGET_ASCENDING, WHERETOGET_DESCENDING, FURTHERINFO_ASCENDING, FURTHERINFO_DESCENDING, UPGRADABLE_ASCENDING, UPGRADABLE_DESCENDING, SPECIAL_ASCENDING, SPECIAL_DESCENDING
	}

	private static class PartComparator implements Comparator<Part> {

		private SortParameter[] parameters;

		private PartComparator(SortParameter[] parameters) {
			this.parameters = parameters;
		}

		@Override
		public int compare(Part part1, Part part2) {
			int comparison;
			for (SortParameter parameter : parameters) {
				switch (parameter) {
				case NAME_ASCENDING:
					comparison = part1.name.compareTo(part2.name);
					if (comparison != 0)
						return comparison;
					break;
				case NAME_DESCENDING:
					comparison = part2.name.compareTo(part1.name);
					if (comparison != 0)
						return comparison;
					break;

				case LEVEL_ASCENDING:
					comparison = ((Integer) part1.level)
							.compareTo(part2.level);
					if (comparison != 0)
						return comparison;
					break;
				case LEVEL_DESCENDING:
					comparison = ((Integer) part2.level)
							.compareTo(part1.level);
					if (comparison != 0)
						return comparison;
					break;

				case SPEED_ASCENDING:
					comparison = ((Integer) part1.speed)
							.compareTo(part2.speed);
					if (comparison != 0)
						return comparison;
					break;
				case SPEED_DESCENDING:
					comparison = ((Integer) part2.speed)
							.compareTo(part1.speed);
					if (comparison != 0)
						return comparison;
					break;

				case HP_ASCENDING:
					comparison = ((Integer) part1.hp)
							.compareTo(part2.hp);
					if (comparison != 0)
						return comparison;
					break;
				case HP_DESCENDING:
					comparison = ((Integer) part2.hp)
							.compareTo(part1.hp);
					if (comparison != 0)
						return comparison;
					break;

				case CAPACITY_ASCENDING:
					comparison = ((Integer) part1.capacity)
							.compareTo(part2.capacity);
					if (comparison != 0)
						return comparison;
					break;
				case CAPACITY_DESCENDING:
					comparison = ((Integer) part2.capacity)
							.compareTo(part1.capacity);
					if (comparison != 0)
						return comparison;
					break;

				case ARMOR_ASCENDING:
					comparison = ((Integer) part1.armor)
							.compareTo(part2.armor);
					if (comparison != 0)
						return comparison;
					break;
				case ARMOR_DESCENDING:
					comparison = ((Integer) part2.armor)
							.compareTo(part1.armor);
					if (comparison != 0)
						return comparison;
					break;

				case WEIGHT_ASCENDING:
					comparison = ((Integer) part1.weight)
							.compareTo(part2.weight);
					if (comparison != 0)
						return comparison;
					break;
				case WEIGHT_DESCENDING:
					comparison = ((Integer) part2.weight)
							.compareTo(part1.weight);
					if (comparison != 0)
						return comparison;
					break;

				case WHERETOGET_ASCENDING:
					comparison = part1.whereToGet
							.compareTo(part2.whereToGet);
					if (comparison != 0)
						return comparison;
					break;
				case WHERETOGET_DESCENDING:
					comparison = part2.whereToGet
							.compareTo(part1.whereToGet);
					if (comparison != 0)
						return comparison;
					break;

				case FURTHERINFO_ASCENDING:
					comparison = part1.furtherInfo
							.compareTo(part2.furtherInfo);
					if (comparison != 0)
						return comparison;
					break;
				case FURTHERINFO_DESCENDING:
					comparison = part2.furtherInfo
							.compareTo(part1.furtherInfo);
					if (comparison != 0)
						return comparison;
					break;

				case ITEMTYPE_ASCENDING:
					comparison = part1.itemType.name().compareTo(
							part2.itemType.name());
					if (comparison != 0)
						return comparison;
					break;
				case ITEMTYPE_DESCENDING:
					comparison = part2.itemType.name().compareTo(
							part1.itemType.name());
					if (comparison != 0)
						return comparison;
					break;

				case UPGRADABLE_ASCENDING:
					comparison = ((Boolean) part1.upgradable)
							.compareTo(part2.upgradable);
					if (comparison != 0)
						return comparison;
					break;
				case UPGRADABLE_DESCENDING:
					comparison = ((Boolean) part2.upgradable)
							.compareTo(part1.upgradable);
					if (comparison != 0)
						return comparison;
					break;

				case SPECIAL_ASCENDING:
					comparison = ((Boolean) part1.special)
							.compareTo(part2.special);
					if (comparison != 0)
						return comparison;
					break;
				case SPECIAL_DESCENDING:
					comparison = ((Boolean) part2.special)
							.compareTo(part1.special);
					if (comparison != 0)
						return comparison;
					break;

				default:
					break;
				}

			}
			return 0;
		}
	}
}
